package marsrovers;

import java.util.HashMap;

public enum Orientation {

	NORTH("N", "W", "E"),
	EAST("E", "N", "S"),
	WEST("W", "S", "N"),
	SOUTH("S", "E", "W");
	
	private final Orientation left;
	private final Orientation right;	
	private final String dir;
	
	Orientation(String dir, String left, String right) {
		this.dir = dir;
		this.left = Orientation.toOrientation(left);
		this.right = Orientation.toOrientation(right);
	}
	
//	NORTH("N"),
//	EAST("E"),
//	WEST("W"),
//	SOUTH("S");
//	
//	
//	private final String dirCode;
	//	private static final HashMap<String, Direction> ALL_DIRECTIONS 
	//		= new HashMap<String, Direction>();
	
//	Orientation(String dirCode) {
//		this.dirCode = dirCode;
//	}
//	
//	public String getDirCode() {
//		return dirCode;
//	}
	
	// TODO(seshumadhav): Implement with a Map by one single lookup instead of if-else
	public static Orientation toOrientation(String dirCode) {
		if (dirCode.equalsIgnoreCase("N")) {
			return Orientation.NORTH;
		} else if (dirCode.equalsIgnoreCase("E")) {
			return Orientation.EAST;
		} else if (dirCode.equalsIgnoreCase("W")) {
			return Orientation.WEST;
		} else if (dirCode.equalsIgnoreCase("S")) {
			return Orientation.SOUTH;
		} else {
			throw new RuntimeException("Invalid Direction Code");
		}
	}
	
	public Orientation adjust(Instruction i) {
		if (i == Instruction.L) {
			return left;
		} else {
			return right;
		}
	}

}
